<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <style>
    td{width: 100px}
  </style>
</head>
<body>
<table border="1">
  <tr><td>照片:</td><td id="head_td"></td></tr>
  <tr><td>姓名:</td><td id="name_td"></td></tr>
  <tr><td>年龄:</td><td id="age_td"></td></tr>
  <tr><td>好友:</td><td id="friends_td"></td></tr>
</table>
<input type="button" value="加载数据" onclick="f()">
<script>
  function f() {
      //得到页面中的td
      let headTd = document.querySelector("#head_td");
      let nameTd = document.querySelector("#name_td");
      let ageTd = document.querySelector("#age_td");
      let friendsTd = document.querySelector("#friends_td");

        //服务器响应的内容如果是一个自定义Java对象,
      // 客户端接收到的数据用一个自定义的JS对象保存
      let person = {name:"传奇哥",age:18,url:"fcq.jpg",friends:["貂蝉","武则天","西施"]};

      //把从服务器得到的数据 展示到页面中
      nameTd.innerText = person.name;
      ageTd.innerText = person.age;

      //创建图片标签
      let img = document.createElement("img");
      img.src = person.url;
      img.width=100;
      headTd.append(img);
      //创建无序列表
      let ul = document.createElement("ul");
      for (let friend of person.friends) {
          let li = document.createElement("li");
          li.innerText = friend;
          ul.append(li);
      }
      friendsTd.append(ul);


  }
</script>
</body>
</html>